﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Pout_Porri.Objects.Interface;
using Pout_Porri.Utils;

namespace Pout_Porri.Objects
{
    class MagicLake : Lake
    {
        private Vector2 scale;
        private float frameRate;
        private double elapsedTime;
        private float dir = -1;

        public MagicLake(Texture2D image, Vector2 position, Vector2 velocity,Boolean Yinverted, float Zorder)
            :base(image, position, velocity, Yinverted, Zorder)
        {
            this.scale = new Vector2(1, 1);   
            this.frameRate = 600;
            currentState = EnemyStates.stand;
        }

        private void lakeGrowShrink(GameTime gameTime, float frameRate)
        {
            if (gameTime.TotalGameTime.TotalMilliseconds > elapsedTime + frameRate)
            {
                elapsedTime = gameTime.TotalGameTime.TotalMilliseconds;

                this.scale.X += dir;

                if (this.scale.X < -0.2f)
                {
                    dir = 0.4f;
                }
                else if (this.scale.X >= -0.2f && this.scale.X <= 0)
                {
                    elapsedTime += 2000;
                    
                }
                else if (this.scale.X >= 1)
                    dir = -0.4f;
            }
            base.scale= this.scale.X;
        }

        public override void configAnimations()
        {
            lakeStand = new Animation("lakeM", new Vector2(336, 84), 100, 0, 0, 1, Axis.X);
            this.addAnimation(lakeStand);

            this.spriteTexture = new Texture2D(Game1.graphics.GraphicsDevice, this.texture.Width, this.texture.Height);

            this.setCurrentAnimation("lakeM");
            currentState = EnemyStates.stand;
        }

        public override void update(GameTime gameTime)
        {
            //Game1.window.Title = "" + this.getImage().Width * this.scale;

            if (currentState == EnemyStates.stand)
            {
                this.spriteTexture = new Texture2D(Game1.graphics.GraphicsDevice, this.texture.Width, this.texture.Height);

                this.setCurrentAnimation("lakeM");
            }

            lakeGrowShrink(gameTime, frameRate);
        }

        public override void draw(SpriteBatch spriteBatch)
        {
            //spriteBatch.Draw(this.getImage(), this.position + Offset, sourceRectangle, Color.White, rotation, Vector2.Zero, scale, spriteEffects, zOrder);
            spriteBatch.Draw(this.getImage(),
                                this.position,
                                null,
                                Color.White,
                                0,
                                new Vector2(150,0),
                                scale, this.spriteEffects, zOrder); 
            //base.draw(spriteBatch);
        }
    }
}
